package com.baizhi.service.impl;

import com.baizhi.dao.NewsDao;
import com.baizhi.entity.News;
import com.baizhi.service.NewsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsDao nd;
    @Override

    public List<News> selectAll() {
        return nd.selectList(null);
    }

    @Override
    public void insert(News news) {
        nd.insert(news);
    }

    @Override
    public News selectOne(int id) {
        return nd.selectById(id);
    }

    @Override
    public void delete(int id) {
        nd.deleteById(id);
    }

    @Override
    public void update(News news) {
        nd.updateById(news);
    }

    @Override
    public List<News> selectByCon(String title, String conent) {
        QueryWrapper<News> wrapper= new QueryWrapper<>();
        wrapper.like("title",title);
        wrapper.like("content",conent);
        return nd.selectList(wrapper);
    }

    @Override
    public PageInfo<News> selectByPage(int pageNo, int pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<News> newsList = nd.selectList(null);
        return new PageInfo<>(newsList);
    }

}
